package com.xbongbong.admin.model.impl;

import com.xbongbong.admin.domain.dao.PaasAppRetainDao;
import com.xbongbong.admin.domain.entity.PaasAppRetainEntity;
import com.xbongbong.admin.model.PaasAppRetainModel;

import com.xbongbong.paas.toolbox.util.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author guohui.zhang
 * @Title:paasAppRetainModel业务实现
 * @date 2020/3/1710:03
 */
@Service("paasAppRetainModel")
public class PaasAppRetainModelImpl implements PaasAppRetainModel {

    private static final String CLOUMNS = "id, old_id, corpid, name, icon,color, saas_mark, alias,enable, display, sort, creator_id, add_time, update_time, del ";
    @Resource
    private PaasAppRetainDao paasAppRetainDao;
    @Override
    public Integer insert(PaasAppRetainEntity entity) {
        return paasAppRetainDao.insert(entity);
    }

    @Override
    public List<PaasAppRetainEntity> list(Map<String, Object> param) {
        param.put("columns", CLOUMNS);
        return paasAppRetainDao.findEntitys(param);
    }

    @Override
    public PaasAppRetainEntity getByKey(Long key, String corpid) {
        return paasAppRetainDao.getByKey(key, corpid);
    }

    @Override
    public Integer delete(Long appId, String corpid) {
        return paasAppRetainDao.deleteByKey(appId, corpid);
    }

    @Override
    public Integer update(PaasAppRetainEntity entity) {
        long now = DateUtil.getInt();
        entity.setUpdateTime(now);
        return paasAppRetainDao.update(entity);
    }

    /**
     * 根据应用安装id查询单个实体
     * @param appInstallId
     * @param corpid
     * @return
     */
    @Override
    public PaasAppRetainEntity getByAppInstallId(Long appInstallId, String corpid) {
        return paasAppRetainDao.getByAppInstallId(appInstallId, corpid);
    }
}
